<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  /*
  *   求一组数中的最大值和最小值，以及所在位置的下标
  */
  
  var arr = [1,2,3,4,5,3,2,8,9,34,21,56,45];
  var min = arr[0];
  var max = arr[0];
  for(var i = 1; i < arr.length; i++){
    min = Math.min(min, arr[i]);
    max = Math.max(max, arr[i]);
  }
  console.log(max, arr.indexOf(max));
  console.log(min, arr.indexOf(min));
  
</script>
</html>